/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.tamnhat.utility.entity;

import com.tamnhat.entity.Product;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import telsoft.admin.util.AppServer;
import telsoft.sql.Database;

/**
 *
 * @author Administrator
 */
public class Billing {
    public String timeStamp;
    public String product_name;
    public String cost;

    public Billing() {
    }

    public String getTimeStamp() {
        return timeStamp;
    }

    public void setTimeStamp(String timeStamp) {
        this.timeStamp = timeStamp;
    }

    public String getProduct_name() {
        return product_name;
    }

    public void setProduct_name(String product_name) {
        this.product_name = product_name;
    }

    public String getCost() {
        return cost;
    }

    public void setCost(String cost) {
        this.cost = cost;
    }
        
    public static List<Billing> getAll(String phoneNumber, String productName, String product_id) throws Exception{
        Connection cn = null;
        PreparedStatement pst = null;
        ResultSet rs = null;
        List<Billing> list = new ArrayList<Billing>();
        try{
            cn = AppServer.getConnection();
            pst = cn.prepareStatement("select to_char(a.timestamp,'dd-mm-yyyy HH:mi:ss'),b.product_name,a.cost "
                    + " from sdp_cdr a, sdp_products b "
                    + " where a.productid = b.sdp_product_code and a.msisdn = ? and b.product_id = ?"
                    + " and a.chargeresult = 1 and a.cost > 0"
                    + " order by a.timestamp");
            
            pst.setString(1, phoneNumber);
            pst.setString(2, product_id);
            
            rs = pst.executeQuery();
            while(rs.next()){
                Billing b = new Billing();
                b.setTimeStamp(rs.getString(1));
                b.setProduct_name(productName);
                b.setCost(rs.getString(3));
                list.add(b);
            }
            return list;
        }finally{
            Database.closeObject(rs);
            Database.closeObject(pst);
            Database.closeObject(cn);
        }
    }
}
